<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"
	  xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<!--<%@ include file="/common/taglibs.jsp" %>-->
<head>
	<title>中国移动云南公司供应链管理系统</title>
	<link rel="stylesheet" th:href="@{/css/login.css}" />
	<script th:src="@{/js/plugins/jquery/jquery.min.js}"></script>
	<script th:src="@{/js/des.js}"></script>
	<!--[if lt IE 9]>
	<script th:src="@{/js/plugins/bootstrap/html5shiv.min.js}"></script>
	<script th:src="@{/js/plugins/bootstrap/respond.min.js}"></script>
	<![endif]-->
	<script type="text/javascript"  th:inline="javascript">/*<![CDATA[*/
    	var access_token = /*[[${access_token}]]*/;
		$(function(){
			$("#j_username").focus();
		});
	 	
	    function trim(text){
	    	return text.replace(/(^\s*)|(\s*$)/g,'');
	    }
	    
	    /*登录模块 */
	    function doSubmit(){
	    	var username = $("#username").val();
	    	var password = $("#password").val();
	    	if(username == null || trim(username) == ""){
	    		alert("用户名不能为空，请输入！");
	    		$("#username").focus();
	    		return;
	    	}else if(password == null || trim(password) == "" || trim(password) == "密码"){
	    		alert("密码不能为空，请输入！");
	    		$("#password").focus();
	    		return;
	    	}
            setpw();
			var loginForm = $("#loginForm").serialize();
            $.ajax({
                url:/*[[@{/oauth/token}]]*/,
                async:true,
                dataType:"json",
                type:"GET",
                data:loginForm,
                success:function(data){

                    //Add authentication headers as params
                /*    var params = {
                        access_token: data.access_token,
                        Authorization: "Bearer "+data.access_token
                    };*/

					//Add authentication headers in URL
                    // var url = [/*[[@{/index}]]*/, $.param(params)].join('?');

					//Open window
                    // window.open(url);

                    // alert("access_token : "+data.access_token);
					var url =/*[[@{/index}]]*/;
					url +="?access_token="+data.access_token;
					// url +="?Authorization=Bearer "+data.access_token+"&access_token="+data.access_token;
                    var infoWindow=window.open(url);
                    // infoWindow.access_token=data.access_token;
                    // infoWindow.setRequestHeader("Authorization","Bearer "+data.access_token);
                    // infoWindow.setRequestHeader("access_token",data.access_token);
                    // window.h
                    // window.open(/*[[@{/index}]]*/ +"?access_token="+data.access_token);
                   // alert(data.access_token);



                }
            });
	    	// $("#submitType").val(3);
            // document.loginForm.submit();
	    	// $("#loginForm").submit();
	    }
	    
		/*密码重置模块 */
	    function resetSubmit(){
	    	$("#resetPwdModel").show();
	    	$("#loginModel").hide();
	    }
		
		function loadLogin(){
			window.location.href = "${ctx}/login";
		}

		function setpw(){
            $("#password").val( encode3des($("#password").val()));
		}
		$(function(){
			$("#back").click(function(){
				loadLogin();
			});
        /*    $("#password").bind('change ', function() {
                setpw()
            });*/

           /* $("#password").change(function(){
                $("#password").val( encode3des($("#password").val()));
            });*/



			
			$("#reset").click(function(){
				var loginName = $("#loginName").val();
				var phone= $("#phone").val();
				if(loginName == null || trim(loginName) == ""){
		    		alert("登录名不能为空，请输入！");
		    		$("#loginName").focus();
		    		return;
		    	}else if(phone == null || trim(phone) == "" || trim(phone) == "手机号"){
		    		alert("手机号不能为空，请输入！");
		    		$("#phone").focus();
		    		return;
		    	}
				
				$.ajax({
					url:"@{/oauth/token}",
					async:true,
					dataType:"json",
					type:"POST",
					data:{"loginName":loginName,"phone":phone},
					success:function(data){
						if(data._state == "1"){
							$("#msgModel").find("font").html(data._msg);
							setTimeout("loadLogin()","3000");
						}else{
							$("#msgModel").find("font").html(data._msg);
						}
					}
				});
			});
		});
    /*]]>*/
</script>
</head>
<body>
	<div class="header">
		<img th:src="@{/images/index/login-logo.png}"  />
	</div>
<div class="section">
    	<div class="login_box">
    	   <div id="loginModel">
    		<div class="title">用 户 登 录</div>
				<form id="loginForm" name="loginForm" method="get" th:action="@{/oauth/token}"  >
					<input class="user" name="username" id="username" type="text" placeholder="用户名" onkeypress="if(event.keyCode==13){doSubmit();}"/>
					<input class="key" name="password" id="password" type="password" placeholder="密码" onkeypress="if(event.keyCode==13){  doSubmit();}"/>
	    			<input type="hidden" name="grant_type"  th:value="${grantType}"/>
	    			<input type="hidden" name="scope"  th:value="${scope}"/>
	    			<input type="hidden" name="client_id"  th:value="${clientName}"/>
	    			<input type="hidden" name="client_secret"    th:value="${clientAuth}"/>
	    			<input type="hidden" name="redirect_url" id="redirect_url"  th:value="@{/index}"/>
					<a id="resetPwd" onclick="resetSubmit()">忘记密码？</a>
					<a id="j_login" class= "show" style="width:80%;" type="button"  onclick="doSubmit()" >登 &nbsp; &nbsp;录</a>
					<div id="msgDiv">

						<!--<c:if test="${not empty param.error}"><br>
					    	<font color="red"><br/>登录错误:</font>  
					    	${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}  		
				        </c:if>-->
					</div>
				</form>
			</div>	
			<div id="resetPwdModel" style="display:none;">
				<div class="title">重 置 密 码</div>
				<form id="resetForm" name="resetForm" method="post" action="">
					<input class="user" name="loginName" id="loginName" type="text" placeholder="登录名" onkeypress="if(event.keyCode==13){doSubmit();}"/>
					<input class="key" name="phone" id="phone" type="text" placeholder="手机号" onkeypress="if(event.keyCode==13){doSubmit();}"/>
					<a id="reset" style="width:30%" class="show" type="button" > 重&nbsp; &nbsp;置</a>
					<a id="back" style="width:30%;margin-left:5%;" class="show" type="button" > 返&nbsp; &nbsp;回</a>
					<div id="msgModel">
					    <font color="red" style="font-size:16px;"><br/></font>  
					</div>
				</form>	
			</div> 
		</div>
</div>
<div class="footer"><span class="mr10"><b>版权所有：</b>中国移动通信集团云南有限公司</span></div>
</body>
<script type="text/javascript">  
if (self != top){ 
	window.top.location = window.location; 
} 
</script>
</html>
